﻿using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace ServiceA.Controllers
{
    [ApiController]
    [Route("/[controller]")]
    public class TestsController : Controller
    {
        private readonly ICapPublisher _capBus;

        public TestsController(ICapPublisher capPublisher)
        {
            _capBus = capPublisher;
        }

        [HttpGet]
        [Route("Index")]
        public IActionResult Index()
        {
            return Ok("ServiceA");
        }

        /// <summary>
        /// 下单 发布下单事件
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        [Route("Create")]
        [HttpGet]
        public async Task<IActionResult> CreateOrderAsync()
        {
            // ...订单保存成功
            await _capBus.PublishAsync("order.services.createorder", "创建订单");
            await _capBus.PublishAsync("order.services.createorder.sms", "发送短信");
            return Ok("订单创建成功");
        }
    }
}
